package com.hss.rxjava.result;


import com.hss.rxjava.CheckInterface;

import java.util.LinkedList;


public class ResultListObject<T>  extends ResultBaseBean {
	public LinkedList<T> response;

	public LinkedList<T> getResponse() {
		return response;
	}

	public int unpaidOrders;//未支付订单数量

	public void setResponse(LinkedList<T> response) {
		this.response = response;
	}


	/**
	 * 检查数据完整性
	 * @param index 0 默认检查方式
	 * @return
	 */
	public boolean check(boolean notNull,int index) {
		if(notNull){
			return response != null && checkAndFix(index);
		}else{
			return response == null || checkAndFix(index);
		}
	}

	private boolean checkAndFix(int index){
		for(T t : response){
			if(t instanceof CheckInterface){
				if(!((CheckInterface) t).check(index)){
					((CheckInterface) t).fix(index);
					if(!((CheckInterface) t).check(index)) return false;
				}
			}else{
				break;
			}
		}
		return true;
	}
}
